package KnowSparkSQL.DSL.DatasetMethods.CreateDataset;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.util.Arrays;
import java.util.List;

public class CreateDataset2 {
    public static void main(String[] args) {
        /**
         * 2. 调用sparkSession.createDataFrame(List<?> data, Class<?> beanClass)创建DataSet<Row>
         */
        SparkSession ss = SparkSession.builder().appName("CreateDataset2").master("local").getOrCreate();

        List<Student> data = Arrays.asList(new Student("张三"), new Student("李四"));

        Dataset<Row> dataFrame = ss.createDataFrame(data, Student.class);
        dataFrame.printSchema();


    }
    public static class Student {
        private String name;

        public Student(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
